home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / volumeid.postinst < prev    next >
Encoding:
Text File  |  2007-04-10  |  4.3 KB  |  204 lines

  1. #!/bin/sh -e
  2. # This script can be called in the following ways:
  3. #
  4. # After the package was installed:
  5. #    <postinst> configure <old-version>
  6. #
  7. #
  8. # If prerm fails during upgrade or fails on failed upgrade:
  9. #    <old-postinst> abort-upgrade <new-version>
  10. #
  11. # If prerm fails during deconfiguration of a package:
  12. #    <postinst> abort-deconfigure in-favour <new-package> <version>
  13. #               removing <old-package> <version>
  14. #
  15. # If prerm fails during replacement due to conflict:
  16. #    <postinst> abort-remove in-favour <new-package> <version>
  17.  
  18.  
  19. # Rewrite /etc/fstab so that filesystems are mounted by UUID
  20. mount_by_uuid_conversion()
  21. {
  22.     if [ -e /etc/fstab.pre-uuid ]; then
  23.     return
  24.     fi
  25.  
  26.     cp -a /etc/fstab /etc/fstab.pre-uuid
  27.     exec 9<&0 8>&1 </etc/fstab >/etc/fstab.new
  28.     trap "rm -f /etc/fstab.new" 0
  29.  
  30.     uuids=""
  31.  
  32.     old_IFS="$IFS"
  33.     IFS="
  34. "
  35.     while read LINE
  36.     do
  37.     IFS="$old_IFS"
  38.     set -- $LINE
  39.     IFS="
  40. "
  41.     DEV=$1 MTPT=$2 FSTYPE=$3 OPTS=$4
  42.  
  43.     # Check the device is sane for conversion
  44.     case "$DEV" in
  45.         ""|\#*)        # Preserve blank lines and user comments
  46.         echo "$LINE"
  47.         continue
  48.         ;;
  49.         LABEL=*|UUID=*)    # Already mounting by LABEL or UUID
  50.             echo "$LINE"
  51.         continue
  52.         ;;
  53.         /dev/disk/*)    # Already mounting by particulars
  54.             echo "$LINE"
  55.         continue
  56.         ;;
  57.         /dev/fd[0-9]*)    # Floppy devices, not mounted by filesystem
  58.             echo "$LINE"
  59.         continue
  60.         ;;
  61.         /dev/mapper/*)    # devmapper devices, already by "label"
  62.             echo "$LINE"
  63.         continue
  64.         ;;
  65.         /dev/evms/*)    # evms devices, already by "label"
  66.             echo "$LINE"
  67.         continue
  68.         ;;
  69.         /dev/md[0-9]*)    # RAID devices, broken
  70.             echo "$LINE"
  71.         continue
  72.         ;;
  73.         /dev/*)        # Ordinary devices -- we want to convert
  74.         if [ -L "$DEV" ] && readlink "$DEV" | grep -q "^/dev/mapper/"; then    
  75.             echo "$LINE"
  76.             continue
  77.         elif [ ! -b "$DEV" ]; then
  78.             echo "$LINE"
  79.             continue
  80.         fi
  81.             ;;
  82.         *)            # Anything else gets left alone
  83.             echo "$LINE"
  84.         continue
  85.     esac 
  86.     
  87.     # Don't convert filesystem types that don't make sense
  88.     case "$FSTYPE" in
  89.         auto)        # Auto detection -- implies non-fixed fs
  90.         echo "$LINE"
  91.         continue
  92.         ;;
  93.     esac
  94.     
  95.     # Check filesystem options also
  96.     case "$OPTS" in
  97.         noauto|*,noauto|noauto,*|*,noauto,*)    # Implies non-fixed
  98.             echo "$LINE"
  99.         continue
  100.         ;;
  101.     esac
  102.  
  103.  
  104.     # If we reach this point, we think we want to move the fstab
  105.     # entry over to mount-by-UUID.  The first check is that the
  106.     # filesystem on the device *has* a uuid
  107.     UUID=$(/sbin/vol_id -u "$DEV" || true)
  108.     if [ -z "$UUID" ]; then
  109.         # Can we generate one?
  110.         if [ "$FSTYPE" = "swap" ]; then
  111.         REAL_FSTYPE=$(/sbin/vol_id -t "$DEV" || true)
  112.         case "$REAL_FSTYPE" in
  113.             swap)    # is a swap device, add a UUID to it
  114.             UUID=$(uuidgen)
  115.             echo -n "$UUID" |
  116.               perl -ne 's/-//g;chomp;print pack "H*",$_' |
  117.               dd conv=notrunc "of=$DEV" obs=1 seek=1036 2>/dev/null
  118.             ;;
  119.             swsusp)    # contains a suspended image, mkswap it!
  120.             if ! mkswap "$DEV" >/dev/null; then
  121.                 echo "Warning: unable to make swap $DEV" 1>&2
  122.                 echo "$LINE"
  123.                 continue
  124.             fi
  125.  
  126.             UUID=$(/sbin/vol_id -u "$DEV" || true)
  127.             if [ -z "$UUID" ]; then
  128.                 echo "Warning: unable to generate uuid for $DEV" 1>&2
  129.                 echo "$LINE"
  130.                 continue
  131.             fi
  132.             ;;
  133.             *)
  134.             echo "Warning: $DEV is not a swap partition" 1>&2
  135.             echo "$LINE"
  136.             continue
  137.             ;;
  138.         esac
  139.         else
  140.         echo "Warning: unable to find a UUID for $DEV" 1>&2
  141.         echo "$LINE"
  142.         continue
  143.         fi
  144.     fi
  145.  
  146.     # Check for duplicates
  147.     case "$uuids" in
  148.     "$UUID" | "$UUID "* | *" $UUID" | *" $UUID "*)
  149.         echo "Error: duplicate UUID $UUID detected" 1>&2
  150.         echo "Unable to migrate /etc/fstab to UUID-based mounting" 1>&2
  151.  
  152.         exec 0<&9 9<&- 1>&8 8>&-
  153.         trap 0
  154.  
  155.         rm -f /etc/fstab.new
  156.         return
  157.         ;;
  158.     *)
  159.         uuids="${uuids:+$uuids }$UUID"
  160.         ;;
  161.     esac
  162.  
  163.     # Now write the new line out
  164.     shift
  165.     echo "# $DEV -- converted during upgrade to edgy"
  166.     echo "UUID=$UUID $@"
  167.     done
  168.     IFS="$old_IFS"
  169.  
  170.     exec 0<&9 9<&- 1>&8 8>&-
  171.     trap 0
  172.  
  173.     mv -f /etc/fstab.new /etc/fstab
  174. }
  175.  
  176. # Update the initramfs
  177. update_initramfs()
  178. {
  179.     update-initramfs -u
  180. }
  181.  
  182.  
  183. case "$1" in
  184.     configure)
  185.     # Upgrade from dapper
  186.     if dpkg --compare-versions "$2" lt "093-0ubuntu5"; then
  187.         mount_by_uuid_conversion
  188.     fi
  189.  
  190.     update_initramfs
  191.     ;;
  192.  
  193.     abort-upgrade|abort-deconfigure|abort-remove)
  194.     ;;
  195.  
  196.     *)
  197.     echo "$0 called with unknown argument \`$1'" 1>&2
  198.     exit 1
  199.     ;;
  200. esac
  201.  
  202.  
  203. exit 0
  204.